<template>
     <section class="jumbotron">
        <h3 class="jumbotron-heading">Search Github Users</h3>
        <div>
            <input ref="inputValue" type="text" placeholder="enter the name you search" v-model="login" @keyup.enter="searchLogin"/>&nbsp;
            <button @click="searchLogin">Search</button>
        </div>
    </section>
</template>

<script>
    import axios from 'axios';
    export default {
        name:'Search',
        data(){
          return{
            login:''
          }
        },
        methods:{
            searchLogin(){
                if(!this.$refs.inputValue.value) return alert("不能为空！")
                this.$bus.$emit('userList',{isFirst:false,isLoading:true,errorMsg:'',users:[]})
                axios.get(`https://api.github.com/search/users?q=${this.login}`).then(
                    response => {
                        console.log('请求成功',response.data.items);
                        this.$bus.$emit('userList',{isFirst:false,isLoading:false,errorMsg:'',users:response.data.items})
                    },
                    error => {
                        console.log('请求失败',error.message);
                        this.$bus.$emit('userList',{isFirst:false,isLoading:false,errorMsg:'error.message',users:[]})
                    }
                )
            }
        }
    }
</script>

<style>

</style>